//
//  ByRegistrationSubjectVC.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/9.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByRegistrationSubjectVC.h"

// view
#import "ByViewRegistrationSubjectHeader.h"

// cell
#import "ByCellRegistrationSubject.h"

@interface ByRegistrationSubjectVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *items;
@end

@implementation ByRegistrationSubjectVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.subject.name;
    [self addLeftBackBarButtonItem];
    [self createViews];
    [self fetchData];
}

#pragma mark - getter
- (NSMutableArray *)items{
    if (!_items) {
        _items = [NSMutableArray array];
    }
    return _items;
}

#pragma mark - fetch data
- (void)fetchData{
    for (int i = 0; i < 10; i ++) {
        ByModelRegistrationDoctor *model = [[ByModelRegistrationDoctor alloc] init];
        model.nick_name = @"测试名称";
        model.address = @"杭州 江干区 名医";
        model.decribeStr = @"医生医生医生医生医生医生医生";
        if (i % 2 == 0) {
            model.status = @"1";
        }else{
            model.status = @"0";
        }
        [self.items addObject:model];
    }
    [self.tableView reloadData];
}

#pragma mark - create views
- (void)createViews{
    ByViewRegistrationSubjectHeader *headerView = [[ByViewRegistrationSubjectHeader alloc] init];
    [self.view addSubview:headerView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 80));
        if (@available(iOS 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        }else{
            make.top.equalTo(self.view.mas_top);
        }
    }];
    // 时间选择
    headerView.selectedBlock = ^(NSDictionary *dic) {
        [ByCoreToolAlert showOnlyText:dic[@"week"]];
        [self fetchData];
    };
    
    self.tableView = [[UITableView alloc] init];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(headerView.mas_bottom);
        make.right.equalTo(@(0));
        if (@available(iOS 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        }else{
            make.bottom.equalTo(self.view.mas_bottom);
        }
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   return  self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByCellRegistrationSubject *cell = [ByCellRegistrationSubject cellWithTableView:tableView];
    cell.model = self.items[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}
@end
